#!/bin/sh -e
# $Id: mk-pkglist-from-cksum.sh 636 2010-01-17 17:19:29Z ant_code $

wd="`pwd`"
time="`date "+%s"`"
tmp_pkglist="$(mktemp -d -p $wd/tmp pkglist.XXXXXX)"
. $wd/env

if [ ! -f "$1" ]; then
	echo ""
	echo -n " Enter path to the CHECKSUMS.md5 file: "
	read cksum_file
fi

cksum_file=${1:-$cksum_file}

if [ -f "$cksum_file"  ]; then
	cp $cksum_file $tmp_pkglist/CHECKSUMS.md5
	# strip with result: "ap/ash-0.4.0-i386-1.tgz" as an example.
	cat $tmp_pkglist/CHECKSUMS.md5 | cut -d" " -f3|sed -e 's/^\.\///g'|grep -E "t[gxbl]z$" > $tmp_pkglist/CHECKSUMS.md5.stage1
	for p in `cat $tmp_pkglist/CHECKSUMS.md5.stage1`; do
		echo $p >> $tmp_pkglist/`dirname $p`.pkglist
	done
fi


# copy pkglists
# default 
dest=$wd/files/installcd-initrd/mostaza/files/packages/pkglist/default
echo " Copying pkglists for 'default' : $dest"
for l in $slackware_pkglist_default ; do
	cp $tmp_pkglist/$l.pkglist $dest
done

# full
dest=$wd/files/installcd-initrd/mostaza/files/packages/pkglist/full
echo " Copying pkglists for 'full' : $dest"
for l in $slackware_pkglist_full ; do
	cp $tmp_pkglist/$l.pkglist $dest
done

# no_x11
dest=$wd/files/installcd-initrd/mostaza/files/packages/pkglist/no_x11
echo " Copying pkglists for 'no_x11' : $dest"
for l in $slackware_pkglist_no_x11 ; do
	cp $tmp_pkglist/$l.pkglist $dest
done

echo ""
echo " The lists are at:  $tmp_pkglist "
echo ""
echo Done.

set +e
